home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / educate / wordy442.zip / UNRF.C < prev    next >
C/C++ Source or Header  |  1996-06-22  |  3KB  |  86 lines

  1. /**************************************************************************/
  2. /*                                                                        */
  3. /*                               UnReFormat                               */
  4. /*                                                                        */
  5. /*                 Reverses effect of ReFormat Utility                    */
  6. /*                       [Back to 1 word / line]                          */
  7. /*                                                                        */
  8. /*                                M\Cooper                                */
  9. /*                               PO Box 237                               */
  10. /*                          St. David, AZ 85630                           */
  11. /*                    E-mail: thegrendel@theriver.com                     */
  12. /*                                                                        */
  13. /**************************************************************************/
  14.  
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <ctype.h>
  18.  
  19. #define MAXFILENAMELEN 40
  20. #define MAXWORDLEN 98
  21. #define TEMPFILE "temp.$x$"
  22. #define COMMANDLINEPRAMS 2
  23.  
  24.    typedef enum { FALSE, TRUE } Boolean;
  25.  
  26.    Boolean unrf( char *file );
  27.  
  28. void main( int argc, char **argv )
  29. {
  30.    char filename [MAXFILENAMELEN];
  31.  
  32.       if( argc == COMMANDLINEPRAMS )
  33.          strcpy( filename,  *( argv + 1 ) );
  34.       else
  35.          {
  36.          printf( "\n\nName of file to UnReFormat? " );
  37.          gets( filename );
  38.          }
  39.  
  40.       if( unrf( filename ) )
  41.          {
  42.          printf( "\n\nFile %s UnReFormatted back to \"standard\" format.\n",
  43.                  filename );
  44.          unlink( filename ); //Delete original file.
  45.          rename( TEMPFILE, filename );
  46.          }
  47.       else
  48.          printf( "\n\nCan't find or create files.\n" );
  49.  
  50. }
  51.  
  52. /***************************************************************************/
  53.  
  54. Boolean unrf( char *fname )
  55. {
  56.    FILE *fsource,
  57.         *fobject;
  58.    char word [MAXWORDLEN];
  59.  
  60.       if( !( fsource = fopen( fname, "r" ) ) )
  61.          return( FALSE );
  62.  
  63.       if( !( fobject = fopen( TEMPFILE, "w" ) ) )
  64.          return( FALSE );
  65.  
  66.          while( !feof( fsource ) )
  67.             {
  68.             if( fscanf( fsource, " %s", word ) == EOF )
  69.                break;
  70.  
  71.             if( isdigit( *word ) )
  72.                break;  //If forgot to delete bottom comment lines...
  73.  
  74.             if( islower ( *word ) )
  75.                fprintf( fobject, "%s\n", word );
  76.              }  
  77.  
  78.  
  79.       fclose( fsource );
  80.       fclose( fobject );
  81.       return( TRUE );
  82. }
  83.  
  84.  
  85.  
  86.